package com.ht.medicaltreatment.viewmodel

import com.hjq.http.EasyHttp
import com.hjq.http.listener.OnHttpListener
import com.ht.medicaltreatment.api.ConsumableApprovalAPI
import com.ht.medicaltreatment.bean.ApplyRecordData
import com.ht.medicaltreatment.bean.ConsumableApplyRecordBean
import com.ht.medicaltreatment.bean.SendListBean
import com.ht.medicaltreatment.bean.SendListData

class SendListViewModel : BaseViewModel() {
    fun requestList(onSuccess:(SendListData)->Unit){
        EasyHttp.post(this)
            .api("/other/app_projectConsumableRecord/findSendRecipientRecord.do")
            .request(object : OnHttpListener<SendListBean> {
                override fun onHttpSuccess(result: SendListBean) {
                    dismissProgress()
                    if(result.code == 200){
                        onSuccess(result.data)
                    }else{
                        dismissProgress(result.message)
                    }
                }

                override fun onHttpFail(e: Exception) {
                    dismissProgress(e.message?:"请求异常")
                }
            })
    }

    fun approval(api: ConsumableApprovalAPI, onSuccess:(ApplyRecordData)->Unit){
        EasyHttp.post(this)
            .api(api)
            .request(object : OnHttpListener<ConsumableApplyRecordBean>{
                override fun onHttpSuccess(result: ConsumableApplyRecordBean) {
                    if(result.code == 200){
                        onSuccess(result.data)
                    }else{
                        dismissProgress(result.message)
                    }
                }

                override fun onHttpFail(e: Exception) {
                    dismissProgress(e.message?:"请求失败")
                }
            })
    }
}
